import {throttle} from 'miniprogram-licia'
Page({
  data:{
    // ! 轮播图数据
    bannerData:[],
    // 热门推荐
    recommendData:[],
    // 最近更新数据
    nowData:[],
    //24小时的篇数
    num_day:0,
    // 一周的篇数
    num_week:0,
    isLoading: false, // 是否正在加载数据
  },
  onShow(){
    this.getData()
    this.getHotData()
    this.getNowData()
  },
 async getData(){
    const res = await wx.http.get('/index/index')
    if(res.errno !==0) return wx.utils.toast()
    this.setData({bannerData:res.data.banner})
  },
  async getHotData(){
    const res = await wx.http.get('/index/hot')
    if(res.errno !==0) return wx.utils.toast()
   this.setData({recommendData:res.data.list})
  },
  async getNowData(page=1,limit=10){
    const {errno,data:{list,num_day,num_week}}= await wx.http.get('/index/new',{page,limit})
    if(errno !==0) return wx.utils.toast()
    this.setData({
      isFinshed:list.totalPages > page,
      nowData:this.data.nowData.concat(list.data)
    })
    this.setData({num_day:num_day,num_week:num_week})
    this._page =page 
  },
   onScorllBotton(){
    if(!this.data.isFinshed) return wx.utils.toast('到底了')
    this.getNowData(++this._page)
  },
})